<?php

use Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel;
use Fisharebest\Webtrees\Http\RequestHandlers\ManageTrees;
use Fisharebest\Webtrees\Http\RequestHandlers\MergeFactsPage;
use Fisharebest\Webtrees\I18N;

?>

<?= view('components/breadcrumbs', ['links' => [route(ControlPanel::class) => I18N::translate('Control panel'), route(ManageTrees::class, ['tree' => $tree->name()]) => I18N::translate('Manage family trees'), $title]]) ?>

<h1><?= $title ?></h1>

<?php foreach ($duplicates as $category => $records) : ?>
    <h2><?= $category ?></h2>

    <?php if (!empty($records)) : ?>
        <ul>
            <?php foreach ($records as $duplicates) : ?>
                <li>
                    <?= $duplicates[0]->fullName() ?>
                    <?php foreach ($duplicates as $record) : ?>
                        —
                        <a href="<?= e($record->url()) ?>">
                            <?= $record->xref() ?>
                        </a>
                    <?php endforeach ?>
                    <?php if (count($duplicates) === 2) : ?>
                        —
                        <a href="<?= e(route(MergeFactsPage::class, ['tree' => $tree->name(), 'xref1' => $duplicates[0]->xref(), 'xref2' => $duplicates[1]->xref()])) ?>">
                            <?= I18N::translate('Merge') ?>
                        </a>
                    <?php endif ?>
                </li>
            <?php endforeach ?>
        </ul>
    <?php else : ?>
        <p><?= I18N::translate('No duplicates have been found.') ?></p>
    <?php endif ?>
<?php endforeach ?>
